package com.wow.app.promotion.web.admin.module.screen;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import com.alibaba.citrus.service.uribroker.URIBrokerService;
import com.alibaba.citrus.turbine.Context;
import com.alibaba.citrus.turbine.Navigator;
import com.alibaba.citrus.turbine.dataresolver.Param;
import com.alibaba.citrus.turbine.uribroker.uri.TurbineURIBroker;
import com.wow.app.biz.common.SessionUser;
import com.wow.app.biz.common.SessionUtil;
import com.wow.app.biz.user.UserService;
import com.wow.app.dal.dto.UserDO;

public class UserList {
	@Resource
	UserService userService;
	@Resource
	URIBrokerService uriBrokerService;

	public void execute(Context context,
			@Param(name = "type", defaultValue = "1") String type,
			HttpSession session, Navigator nav) {
		SessionUser sessionUser = SessionUtil.getSessionUser(session);
		if (sessionUser != null && type != null
				&& Integer.parseInt(sessionUser.getUserType()) == 0) {
			List<UserDO> userList = userService.getUserListByType(Integer
					.parseInt(type));
			context.put("userList", userList);
		} else {
			TurbineURIBroker broker = (TurbineURIBroker) uriBrokerService
					.getURIBroker("openModule");
			String url = broker.setTarget("error.vm")
					.addQueryData("msg", "NO_PEM").render();
			nav.redirectToLocation(url);
		}
	}
}